package com.ddtech.framework.monitor.consolelog;

import ch.qos.logback.classic.filter.LevelFilter;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.spi.FilterReply;
import lombok.extern.slf4j.Slf4j;

import java.text.DateFormat;
import java.util.Date;

/***
 *
 * 描述：
 * 作者： 普斌
 * 日期： 2019/12/6 17:40
 */
@Slf4j
public class LogFilter extends LevelFilter {
    @Override
    public FilterReply decide(ILoggingEvent event) {
        ConsoleLog loggerMessage = new ConsoleLog(
                event.getMessage(),
                DateFormat.getDateTimeInstance().format(new Date(event.getTimeStamp())),
                event.getThreadName(),
                event.getLoggerName(),
                event.getLevel().levelStr);
        ConsoleLogQueue.getInstance().push(loggerMessage);
        return FilterReply.ACCEPT;
    }
}